clear textprogressbar; clear;
getSession;
sess.connect_device
zi=sess.getDevice('dev3567');
rg=EquipmentControl.SignalSource.RigolDG4202('dg4202',  'visa-tcpip', 'TCPIP0::192.168.1.121::inst0::INSTR');
%%
scp=zi.scopeModule();

%% Single Shot - Free Run (non-trigger)
for highVolt = 1:0.5:5
    rg.setWaveHigh(2, highVolt); pause(1);
    fprintf('Volta=%3.2f V\n', highVolt);
    
    scp.reset();

    % Control Panel
    scp.setMode('time');
    % scp.setMode('frequency');
    scp.setSamplingRate(0); 
    scp.setFrameLength(10e-3);
    scp.enableChannel('1');
    scp.inputSelect('0', 0);
    % scp.inputSelect('1', 12);
    scp.setAveraging(1);

    % Trig Panel
    % Choose one aquisition mode
    %----------------------------
    %scp.disableTrigger().setSingleShot();                                % single-shot, free-run (non-trigger)
    scp.enableTrigger().setTimeOut(10.0).setSingleShot();                % single-shot, trigger
    % scp.disableTrigger().setContinuousAcquisition(20.0);                   % continuous, free-run (non-trigger)
    % scp.enableTrigger().setTimeOut(10.0).setContinuousAcquisition(20.0); % continuous, trigger
    %----------------------------
    scp.setTriggerChannel(2);
    scp.setTriggerSlope(1);
    scp.setTriggerLevel(1);
    scp.setTriggerHysteresis(0.010);
    scp.disableTriggerGating();
    scp.setTriggerHoldoff(0.0);
    scp.setTriggerReference(0.0);
    scp.setTriggerDelay(0.0);

    % run
    scp.subscribeChannel();
    scp_data=scp.run();
    scp.unsubscribeChannel();
    
    sess.addData('varHighVoltAverage1', scp_data);
    pause(1);
end
%%
scopeData = sess.getBufferData('varHighVoltAverage1');
for k = 1:9
    rawData = scopeData(k).data.getNodeData();
    
    minVal = mean(rawData.value(1:20));
    maxVal = mean(rawData.value(150000:200000));
    
    loglog(rawData.time, 1-(rawData.value-minVal)/(maxVal-minVal) ); hold on; grid on;
end